﻿<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Maximal sequence of equal elements</title>
    <link href="styles/js-console.css" rel="stylesheet" />
</head>
<body>
    <div id="js-console"></div>
	<script src="scripts/js-console.js"></script>

    <script>
        var array = [2,2,2,2,2,2,3,1,4,3];
        var currentCount = 1;
        var totalCount = 1;
        var targetElement = 0;

        for (var i = 0; i <array.length-1; i++)
        {
            if (array[i]==array[i+1])
            {
                currentCount++;
                if (currentCount>=totalCount)
                {
                    totalCount = currentCount;
                    targetElement = array[i];
                }
            }
            else
            {
                currentCount = 1;
            }  
        }

        jsConsole.write("==> {");
        for (var j = 1; j <= totalCount; j++)
        {
            jsConsole.write(targetElement);
            if (j<totalCount)
            {
                jsConsole.write(", ");
            }
        }
        jsConsole.write("}.");
        jsConsole.writeLine();
    </script>
</body>
</html>
